#ifndef DECODEVIDEO_H
#define DECODEVIDEO_H

#include<QThread>
#include<QImage>
#include<QDebug>
#include<QDateTime>
#include <QMutex>
#include<QList>
#include<atomic>
#include<QCameraInfo>
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavdevice/avdevice.h"
#include "libavfilter/avfilter.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "libpostproc/postprocess.h"
#include "libswresample/swresample.h"
#include "libswscale/swscale.h"
}
class DecodeVideo : public QThread
{
    Q_OBJECT
public:
    DecodeVideo();
    void decoding();
    int getSpeed() const;
    void setSpeed(int value);
    void filePrepare(QString str,bool calculateFrames_=true);

    QString getFilepath() const;
    void setFilepath(const QString &value);

    void initYUY();



private:
    void run();
    QImage img;
    int speed;
    int prevSpeed;

public:
    QString filepath;
    AVFormatContext* formatContex;
    AVCodecContext*codecContext;
    AVCodec*decoder;
       AVPacket*pkt;
       AVFrame*pictureRGB;
       AVFrame*pictrue;
       SwsContext*SwsContextRGB;
       uint8_t *bufferRGB;
       int video_input=-1;


       AVFrame*pictureYUV;
       int imgBYteYUV;
       uint8_t*bufferYUV;
       SwsContext*SwsContextYUV;
       bool calculateFrames=true;
       int size;

       bool st=0;
       bool isone=1;
       bool isStop=0;
       bool isRuning=0;
       int totalFrames=0;


       int x=0;//帧数
       int totalx=0;
       QString video_img_path;




       int wight;
       int hight;

        bool getSt() const;
        void setSt(bool value);

        QImage getImg() const;
        void setImg(const QImage &value);

        bool getIsStop() const;
        void setIsStop(bool value);

        QString getVideo_img_path() const;
        void setVideo_img_path(const QString &value);

        int getX() const;
        void setX(int value);

        int getPrevSpeed() const;
        void setPrevSpeed(int value);

        int getTotalFrames() const;
        void setTotalFrames(int value);

        bool getCalculateFrames() const;
        void setCalculateFrames(bool value);

        int getWight() const;
        void setWight(int value);

        int getHight() const;
        void setHight(int value);

        int getTotalx() const;
        void setTotalx(int value);

signals:
        void sendImage(QImage img,int x);
        void sendYUV(AVFrame* a);
        void sendclose();
        void sendMaxTime();

public slots:
    void stopDecode();

    void SetXToBegin();
};

#endif // DECODEVIDEO_H
